home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / 13h_kit / images.doc < prev    next >
Text File  |  1991-07-04  |  15KB  |  351 lines

  1. >>>IMAGES.DOC
  2.  
  3. A. Copyright Information
  4.  
  5. Images.Hpp and Images.Cpp along with this document file are copyright 1991
  6. by the Gamers Programming Workshop, GAMERS forum, Compuserve (GO GAMERS,
  7. section 11). The code and related document are free for use, distribution,
  8. and modification, provided the following conditions are met:
  9.  
  10.     1. no commercial use of this source code or documents is permitted.
  11.     2. no fee may be charged beyond disk duplication cost for any of this
  12.        material.
  13.     3. If the code is upgraded or modified a copy of the modification must
  14.        be uploaded to section 11 of the GAMERS forum on Compuserve. All
  15.        modifications must be documented and the author's name included in
  16.        the source code header block, and the subsequent file package must
  17.        include all the original doc files as well as any additions. If you
  18.        modify or add functions please update the function list below.
  19.  
  20.  
  21. B. Description
  22.  
  23. Images.hpp and images.cpp provide basic tools for working in graphics mode
  24. 13h, the 256 color standard vga mode, which has become the most popular for
  25. producing high quality gaming software. The following files are required to
  26. use the tools in this package:
  27.  
  28.     IMAGES.HPP   - the image tools header file
  29.     IMAGES.CPP   - image tools function definitions
  30.     KEYBOARD.HPP - low level keyboard interface header file
  31.     KEYBOARD.CPP - functions required by the font class in images.hpp
  32.  
  33. A demo of the functions in this package is included, as IDEMO.EXE.
  34.  
  35. NOTE: Compile these modules in the Large model (pointers default to far).
  36.  
  37. C. Function interface
  38.  
  39. *****************************************************************************
  40. *****************************************************************************
  41.  
  42. The following functions are proto'd in IMAGES.HPP and, defined in
  43. IMAGES.CPP:
  44.  
  45. *****************************************************************************
  46. *****************************************************************************
  47.  
  48. void unpackpcx(FILE *pcx, const char far *source,
  49.                char far *dest, unsigned int num_bytes);
  50.  
  51. Originally used for all PCX unpacking this function was retained when the
  52. pcx class was created so that anyone who needs it will have access to a basic
  53. rle unpacking algorithm for PCX files. It will unpack from a disk file or
  54. a source buffer, depending on which of pcx and source has a valid pointer.
  55. It is illegal for both of these pointers to be NULL, or for both to be valid.
  56. Unpacks num_bytes of data to memory at dest.
  57.  
  58. *****************************************************************************
  59.  
  60. void setgraphmode();
  61.  
  62. setgraphmode() calls interrupt 0x10, function 0x13 to set mode 0x13 graphics
  63. (320 x 200 x 256 colors)
  64.  
  65. *****************************************************************************
  66.  
  67. void settextmode();
  68.  
  69. settextmode() calls interrupt 0x10, function 0x13 to set 80 x 25 x 16 text
  70. mode.
  71.  
  72. *****************************************************************************
  73.  
  74. void wait_vbi();
  75.  
  76. wait_vbi() returns when it senses the start of the next full vertical blank-
  77. ing interval. Use before writing to video ram in order to prevent snow and
  78. flickering. In performance sensitive functions you'll probably want to copy
  79. this short bit of asm code into the function to eliminate the call overhead.
  80.  
  81. *****************************************************************************
  82.  
  83. void reporterr(char type, char where[30]);
  84.  
  85. reporterr() is used to reset text mode and report the particulars of an
  86. error in the images module to the screen. Pass it the result of the offending
  87. function, and a message describing where the error occured. I make no claims
  88. that this is a great error handling system. Feel free to implement your own.
  89.  
  90. *****************************************************************************
  91.  
  92. void loadpalette(int start, int number, const p_rec palette);
  93.  
  94. loadpalette() accesses the DAC directly, and loads number palette registers
  95. beginning with register start. Values loaded are taken from palette. See
  96. the p_rec type defined in IMAGES.HPP.
  97.  
  98. *****************************************************************************
  99.  
  100. void readpalette(int start, int number, p_rec palette);
  101.  
  102. readpalette() accesses the DAC directly, and reads number palette registers
  103. into palette beginning with register start. See p_rec type defined in
  104. IMAGES.HPP
  105.  
  106. *****************************************************************************
  107.  
  108. void clrpalette(int start, int number);
  109.  
  110. clrpalette() clears number palette registers beginning with register start.
  111. Registers are cleared to 0.
  112.  
  113. *****************************************************************************
  114.  
  115. void fadepalettein(int start, int count, const p_rec palette);
  116.  
  117. fadepalettein() does a 64 pass DAC palette fade. It is called by the pcx::
  118. display() member function, and may be called by any other function as well.
  119. Clear the palette first, and then place the image data in the video buffer,
  120. then call this function, which will fade the image in smoothly. Operates on
  121. count registers beginning with register start. See type p_rec defined in
  122. IMAGES.HPP
  123.  
  124. *****************************************************************************
  125.  
  126. void fadepaletteout(int start, int count);
  127.  
  128. fadepaletteout() removes an image from screen by fading the palette registers
  129. to zero. Operates on count registers beginning with register start.
  130.  
  131. *****************************************************************************
  132.  
  133. void setgraphseg(unsigned newseg);
  134.  
  135. setgraphseg() sets the value of the GRAPH_SEG global variable (declared in
  136. IMAGES.CPP to the desired value. All image routines that write or read
  137. video memory (with the exception of the fades, wipes, and dissolves) assume
  138. the video buffer begins at offset 0 of the segment contained in GRAPH_SEG.
  139. This is usefull for redirecting the functions to operate on a virtual screen
  140. in system ram.
  141.  
  142. *****************************************************************************
  143.  
  144. void clearscr(int color);
  145.  
  146. clearscr() clears the entire screen to the passed color. Assumes video buffer
  147. at GRAPH_SEG.
  148.  
  149. *****************************************************************************
  150.  
  151. void barfill(int tlx, int tly, int brx, int bry, int color);
  152.  
  153. barfill() fills the rectangle bounded by top left coord (tlx,tly), and
  154. bottom left coord (blx,bly) with color. Assumes video buffer at GRAPH_SEG
  155.  
  156. *****************************************************************************
  157.  
  158. void writepixel(int x, int y, int color);
  159.  
  160. writepixel() sets the color of the pixel at x,y. Color must be in the range
  161. 0..255. Assumes video buffer at GRAPH_SEG.
  162.  
  163. *****************************************************************************
  164.  
  165. char readpixel(int x, int y);
  166.  
  167. readpixel() returns the color value of the pixel at x,y. Color will be in
  168. the range 0..255. Assumes video buffer at GRAPH_SEG.
  169.  
  170. *****************************************************************************
  171.  
  172. void far *xy_to_ptr(int x, int y);
  173.  
  174. xy_to_ptr returns a pointer to video memory at the location of pixel x,y.
  175. Assumes video buffer at GRAPH_SEG.
  176.  
  177. *****************************************************************************
  178.  
  179. void line(int x0, int y0, int x1, int y1, int color);
  180.  
  181. line() draws a line one pixel wide from (x0,y0) to (x1,y1) in color. Color
  182. must be in the range 0..255. Assumes video buffer at GRAPH_SEG. This func-
  183. tion could stand the addition of line styles and widths.
  184.  
  185. *****************************************************************************
  186.  
  187. void getimage(int x0, int y0, int x1, int y1, char far *buff);
  188.  
  189. getimage() grabs the video data in the rectangle bounded by top left coord
  190. (x0,y0) and bottom right coord (x1,y1) and puts it in memory starting with
  191. the location pointed to by buff. This is a 2d to linear translation, in
  192. other words the image lines are stored consecutively in the buffer.
  193.  
  194. *****************************************************************************
  195.  
  196. void putimage(int x0, int y0, int x1, int y1, char far *buff);
  197.  
  198. putimage() writes the image starting at memory location buff to screen in
  199. the rectangle bounded by top left coord (x0,y0) and bottom right coord
  200. (x1,y1). This is a linear to 2d translation.
  201.  
  202. *****************************************************************************
  203.  
  204. void copyimage(int x0, int y0, int x1, int y1, int putx, int puty,
  205.                void far *src_buf);
  206.  
  207. copyimage() moves an image bounded by top left coord (x0,y0), and bottom
  208. right coord (x1,y1) from the src_buff to the video buffer (assumes GRAPH_
  209. SEG). This is a 2d to 2d translation. In other words, the image is pulled
  210. from a rectangle in src_buf and blitted to a rectangle in the video buffer
  211. at top left coord (putx,puty).
  212.  
  213. *****************************************************************************
  214.  
  215. void doSplitVerticalWipe(void far *pic_buf);
  216.  
  217. doSplitVerticalWipe() moves the image in pic_buf to the video buffer using a
  218. wipe from right and left towards center. If pic_buf == NULL it clears the
  219. screen to 0 using the same wipe.
  220.  
  221. *****************************************************************************
  222.  
  223. void doSplitHorizWipe(void far *pic_buf);
  224.  
  225. doSplitHorizWipe() moves the image in pic_buf to the video buffer using a
  226. wipe from top and bottom towards center. If pic_buf == NULL it clears the
  227. screen to 0 using the same wipe.
  228.  
  229. *****************************************************************************
  230.  
  231. void doSlideVerticalWipe(void far *pic_buf);
  232.  
  233. doSlideVerticalWipe() moves the image in pic_buf to the video buffer by
  234. sliding two halves of the image in from left and right towards the center.
  235. Takes no action if pic_buf == NULL. This function is not perfect, even though
  236. it's highly optimized. For most images the wipe is jittery toward the end.
  237. Even so, it's an impressive effect, so test your images with it before you
  238. discard it. On faster machines it should work fine, there's just a lot of
  239. memory moves to be made in very short intervals.
  240.  
  241. *****************************************************************************
  242.  
  243. void doSlideHorizWipe(void far *pic_buf);
  244.  
  245. doSlideHorizWipe() is similar to doSlideVerticalWipe, except that the two
  246. halves of the image slide in from top and bottom. Also pretty impressive
  247. this function is a little less performance sensitive than the one above
  248. because the lines being copied live in linear memory addresses, unlike above
  249. where rows are copied, and not lines.
  250.  
  251. *****************************************************************************
  252.  
  253. void doVerticalDissolve(void far *pic_buf);
  254.  
  255. doVerticalDissolve() moves the image in pic_buf to the video buffer using
  256. expanding vertical bands. If pic_buf == NULL then the screen is cleared in
  257. the same manner.
  258.  
  259. *****************************************************************************
  260.  
  261. void doHorizDissolve(void far *pic_buf);
  262.  
  263. doHorizDissolve() is similar to doVerticalDissolve, except that it uses
  264. expanding horizontal bands. Also clears the video buffer is pic_buf == NULL.
  265.  
  266. *****************************************************************************
  267.  
  268. void doSparkleDissolve(void far *pic_buf);
  269.  
  270. doSparkleDissolve is not implemented as of July 5, 1991. It will eventually
  271. move the image in pic_buf to the video buffer by doing a pseudo random
  272. pixel placement.
  273.  
  274. ****************************************************************************
  275.  
  276. D. Classes defined in Images.Hpp
  277.  
  278. In addition to the above functions there are four classes defined as part
  279. of the images toolkit. These are a font class, window class, images class,
  280. pcx class, and stack class. See FONT.DOC, WIN.DOC, and PCX.DOC for an expl-
  281. anation of the interface with these object types. Stack class is not docum-
  282. ented at this point, since it is not used.
  283.  
  284. E. Constants
  285.  
  286. // image fade constants ***************************************************
  287.  
  288. const char SnapWipe = 0;             // simple block copy to vram
  289. const char SplitVerticalWipe = 1;    // fades from top and bottom
  290. const char SplitHorizWipe = 2;       // fades from right and left
  291. const char SlideVerticalWipe = 3;    // slides image in from right and left
  292. const char SlideHorizWipe = 4;       // slides image in from top and bottom
  293. const char VerticalDissolve = 5;     // fades multiple vertical slices
  294. const char HorizDissolve = 6;        // fades multiple horizontal slices
  295. const char SparkleDissolve = 7;      // fades with random pixel placement
  296. const char SoftFade=8;                 // does a palette shifted fade
  297.  
  298. // error reporting constants **********************************************
  299.  
  300. const char NoErr = 0;            // no error occured
  301. const char MemErr = 1;           // error occured allocating memory
  302. const char FileReadErr = 2;      // error occured reading a file
  303. const char FileWriteErr = 3;     // error occured writing a file
  304. const char FileMakeErr = 4;      // error occured creating a file
  305. const char FileOpenErr = 5;      // error occured opening file
  306. const char FileFormatErr = 6;    // bad file format error
  307. const char SecondaryErr = 7;     // error occured in subroutine during call
  308. const char UnknownErr = 8;       // an unknown error occured
  309.  
  310. // For use with type PRec *************************************************
  311.  
  312. const short Red = 0;               // constants used with type PRec
  313. const short Green = 1;             // example: PRec Palette;
  314. const short Blue = 2;               //          Palette[0][Green]=63;
  315.  
  316. // for use with call to pcx::load() ***************************************
  317.  
  318. const char Packed = 0;             // load image in compressed form
  319. const char Unpacked = 1;           // load image in uncompressed form
  320. const char Bestfit = 2;            // load compressed or uncompressed
  321.  
  322. F. Static Variables
  323.  
  324. static unsigned int GRAPH_SEG = 0xA000; // segment for video operations
  325. static p_rec current;                   // palette record for fades
  326.  
  327. G. Pros and Cons
  328.  
  329. For the most part this module is in very good working order. I know of no
  330. serious bugs in the works at this point. There are several areas which need
  331. further work, though. The whole module treats background color very simply,
  332. it assumes that the background is always palette value 0. This is true for
  333. fadeouts, font transparency, etc. A better way would be to store the back-
  334. ground value, and provide an interface through setbackgroundclr() function.
  335. Then use this value in all functions that need to know the background color.
  336.  
  337. Another area which needs work is the font capturing. There is a very rudi-
  338. mentary capture program included which will allow you to draw fonts in PCX
  339. format and capture them, but a far better method would be to write a font
  340. design program. The fonts are also fairly fat (the included font in 4k). A
  341. lot of this is due to storing the background. Some sort of delta compression
  342. of the font data would be usefull to reduce this size. I'd welcome any one
  343. who wants to make improvements to any of this code.
  344.  
  345. H. Support.
  346.  
  347. If you have a problem using these routines, please leave a message to
  348. 76605,2346 Mark Betz in the Game Desing section (sec. 11) of the Gamers
  349. Forum on Compuserve. I'm sorry, but no support can be provided by telephone
  350. or by e-mail.
  351.